package com.renzhebiao.lkang.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.plugins.Page;
import com.renzhebiao.lkang.base.BaseService;
import com.renzhebiao.lkang.entity.ContactPO;
import com.renzhebiao.lkang.mapper.ContactMapper;
import com.renzhebiao.lkang.page.PageDTO;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.ContactQuery;
import com.renzhebiao.lkang.request.RequestCache;
import com.renzhebiao.lkang.service.IContactService;
import com.renzhebiao.lkang.utils.BeanCopys;

/**
 * <p>
 * 联系表 服务实现类
 * </p>
 *
 * @author renzhebiao123
 * @since 2018-10-23
 */
@Service
public class ContactService extends BaseService<ContactPO> implements IContactService {

    @Autowired
    ContactMapper contactMapper;

    @Override
    public void add(ContactPO po) {
        po.allEx(RequestCache.userId());
        this.contactMapper.insert(po);
    }

    @Override
    public void edit(ContactPO po) {
        po.updated(RequestCache.userId());
        this.contactMapper.updateById(po);
    }

    @Override
    public void delete(Long id) {
        this.deleteByLogic(id, ContactPO.class);
    }

    @Override
    public List<ContactPO> getContactList(ContactQuery po) {

        return this.contactMapper.selectByMap(BeanCopys.toMap(po));
    }

    @Override
    public ContactPO getContact(Long id) {

        return this.contactMapper.selectById(id);
    }

    @Override
    public PageDTO<ContactPO> getContactByPage(PaginationDTO<ContactQuery, Void> paging) {

        Page<ContactPO> page = this.getPage(paging);
        List<ContactPO> pos = this.contactMapper.getContactByPage(page, page.getCondition());
        return this.getPage(page, pos);
    }

}
